var waybill_salelist = {
    init: function() {
        var that = this;
        $.ajax({
            url: COMMONURL + "api/bidload/GetTranspotList?token=" + $.cookie('token'),
            type: "post",
            data: {
                page: 1,
                pagesize: 20
            },
            dataType: "json"
        }).done(function(redata) {
            if (redata.recode == '0000') {
                var compiled = _.template($("#waybillSaleTpl").html());
                var odata = redata.mod.Items;
                // alert(that.format(odata[0].start_bid_time))
                for (var i = 0, length = odata.length; i < length; i++) {
                    odata[i].start_bid_time = that.format(odata[i].start_bid_time);
                    odata[i].end_bid_time = that.format(odata[i].end_bid_time);
                    odata[i].consignee_time=that.format(odata[i].consignee_time);
                    odata[i].load_time=(odata[i].load_time!=null && odata[i].load_time!='')?odata[i].load_time.replace('T',' ').replace('Z',''):'';
                }
                $("#waybillSaleCon").html(compiled(odata));

                //查看详情
                $('[name="infoModel"]').click(function() {
                    $("#saleList").hide();
                    $("#waybill_salelist").append($("#infoModel").html());
                    that.info();
                });


                $("#pageSalelist ").jqPaginator({
                    totalPages: Math.ceil(redata.mod.TotalNum / 20),
                    visiblePages: 5,
                    currentPage: 1,
                    first: '<li class="first"><a href="javascript:void(0);">首页<\/a><\/li>',
                    prev: '<li class="prev"><a href="javascript:void(0);"><i class="arrow arrow2"><\/i>上一页<\/a><\/li>',
                    next: '<li class="next"><a href="javascript:void(0);">下一页<i class="arrow arrow3"><\/i><\/a><\/li>',
                    last: '<li class="last"><a href="javascript:void(0);">末页<\/a><\/li>',
                    page: '<li class="page"><a href="javascript:void(0);">{{page}}<\/a><\/li>',
                    onPageChange: function(num) {
                        if (num != 1) {
                            that.init();
                        }
                    }
                });

            } else if (redata.recode == '1001') {
                $("#waybillSaleCon").html('暂无销售数据').css('text-align','center');
            }
        });
    },
    info: function() {
        //tab change
        $('body').on('click', '[data-name="tabChange"] a', function() {
            var _self = $(this),
                name = _self.attr("name");
            _self.addClass('cur').siblings("a").removeClass('cur');
            $('#' + name).show().siblings('div').hide();
        });



        //关闭详情
        $("body").on('click', '#closeInfo', function() {
            $("#saleList").show();
            $("#infoModelTpl").remove();
        });

        //关闭标单
        $('body').on('click', '#closeBillModel', function() {
            var button = $(event.relatedTarget),
                itemid = button.data('itemid'),
                modal = $(this);
            $("#closeBillModelTpl").show();
        });
        /*
        $('#closeBillModel').on('show.bs.modal', function(event) {
            var button = $(event.relatedTarget),
                itemid = button.data('itemid'),
                modal = $(this);
        });
        */
    },
    format: function(nS) {
       //return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
             // return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17);
                if(!nS) return null;
            var date = new Date(nS*1000);
            var year = date.getFullYear();
            var month = date.getMonth()+1;
            var d = date.getDate();
            var hours = date.getHours();
            var minutes = date.getMinutes();
            var seconds = date.getSeconds();
            return year+'-'+month+'-'+d+' '+hours+':'+minutes;
    }
}

waybill_salelist.init();
